package com.test.多线程;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.FutureTask;

public class Main {
	public static void main(String[] args) {
		TestThread thread = new TestThread();
		thread.start();

		Thread thread1 = new Thread(new Runnable() {
			@Override
			public void run() {
				System.out.println("runnable run...");
			}
		});
		thread1.start();

		Thread thread2 = new Thread() {
			@Override
			public void run() {
				super.run();
				System.out.println("run2");
			}
		};

		thread2.start();
		System.out.println("----------------------------------------");

		Callable callable = Executors.callable(new Runnable() {
			@Override
			public void run() {
				System.out.println("callable");
			}
		},"456");


		FutureTask futureTask = new FutureTask(callable);
		FutureTask futureTask1 = new FutureTask(new Callable() {
			@Override
			public Object call() throws Exception {
				Thread.sleep(5000);
				return "123";
			}
		});
		Thread thread3 = new Thread(futureTask1);
		thread3.start();
		try {
			Object o = futureTask1.get();
			System.out.println(o);
			for (int i = 0; i < 10; i++) {
				System.out.println("i = " + i);
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}
	}
}
